package cn.doourbest.learnspring.postgre;


import org.postgresql.Driver;
import org.postgresql.jdbc.PgConnection;
import org.postgresql.jdbc.PgResultSet;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @description:
 * @author: zhangsc
 * @create: 2019/12/23
 */

public class PostSql {


    public static void main(String[] args) throws SQLException {

        Driver driver = new Driver();
        Properties properties = new Properties();
        properties.setProperty("user","postgres");
        properties.setProperty("password","123456");
        Connection connect = driver.connect("jdbc:postgresql://localhost:5432/postgres?characterEncoding=utf-8", properties);
        PreparedStatement preparedStatement = connect.prepareStatement("select * from student");

        PgResultSet resultSet = (PgResultSet) preparedStatement.executeQuery();
        ResultSetMetaData rsmd = resultSet.getMetaData();
        String name = rsmd.getColumnName(1);
        System.out.println(name);
        System.out.println(resultSet.getObject(0));
    }
}
